package com.test.service;

import com.test.entity.User;
import org.springframework.http.HttpHeaders;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import static org.springframework.http.RequestEntity.get;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import java.net.URI;
import java.util.List;

@Service
public class UserService {

    private RestTemplate restTemplate = new RestTemplate();

    public List<User> getUser(){
        URI uri = URI.create(String.format("http://%s/user/get", "localhost:8104"));
        RequestEntity<Void> request = get(uri).header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON_VALUE).build();
        return restTemplate.exchange(request, List.class).getBody();
    }
}
